package com.guan.poi.core;

import lombok.Setter;
import lombok.experimental.Accessors;
import org.apache.poi.ss.usermodel.IndexedColors;

import java.util.function.Function;

/**
 * 样式
 */
@Setter
@Accessors(chain = true)
public class DynamicStyle<F> extends PoiStyle {

    /** 动态cell字体*/
    private Function<F, String> dFontName;
    /** 动态cell字体大小*/
    private Function<F, Short> dFontSize;
    /** 动态cell字体大小*/
    private Function<F, Boolean> dFontBold;
    /** 动态cell字体色*/
    private Function<F, IndexedColors> dFontColor;
    /** 动态cell背景色*/
    private Function<F, IndexedColors> dBgColor;
    /** 格式 */
    private Function<F, String>  dStyleFormat;

    /**
     * 解析动态样式
     */
    public DynamicStyle<F> parserDynamic(F object) {
        if(dFontName != null) {
            setFontName(dFontName.apply(object));
        }
        if(dFontSize != null) {
            setFontSize(dFontSize.apply(object));
        }
        if(dFontBold != null) {
            setFontBold(dFontBold.apply(object));
        }
        if(dFontColor != null) {
            setFontColor(dFontColor.apply(object));
        }
        if(dBgColor != null) {
            setBgColor(dBgColor.apply(object));
        }
        if(dStyleFormat != null) {
            setStyleFormat(dStyleFormat.apply(object));
        }
        return this;
    }
}
